package com.monitor.service.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.monitor.dao.ErpCustomerCarMapper;
import com.monitor.dao.ErpDriverMapper;
import com.monitor.dao.ErpTpmsTireInformationCarMapper;
import com.monitor.entity.ErpCustomerCar;
import com.monitor.entity.ErpDriver;
import com.monitor.entity.ErpTpmsTireInformationCar;
import com.monitor.service.ErpTpmsTireInformationCarService;
import com.monitor.util.Result;

@Service
@Transactional
public class ErpTpmsTireInformationCarServiceImpl  extends ServiceImpl<ErpTpmsTireInformationCarMapper, ErpTpmsTireInformationCar> implements ErpTpmsTireInformationCarService  {
	
	@Resource
	private ErpTpmsTireInformationCarMapper erpTpmsTireInformationCarMapper;
	
	@Resource
	private ErpCustomerCarMapper erpCustomerCarMapper;
	
	@Resource
	private ErpDriverMapper erpDriverMapper;
	
	@Override
	public Result<Map<String, Object>> selectByCarId(int carId) {
		// TODO Auto-generated method stub
		try {
			Map<String, Object> map=erpTpmsTireInformationCarMapper.selectByCarId(carId);
			ErpCustomerCar car=erpCustomerCarMapper.selectById(carId);
			if(car!=null) {
				map.put("carPlate", car.getCarPlate());
				map.put("carNumber", car.getCarNumber());
				ErpDriver ed=erpDriverMapper.selectByCarNumber(car.getCarPlate());
				if(ed!=null) {
					map.put("guaPlate", ed.getTrailerNumber());
					car=erpCustomerCarMapper.selectByPlate(ed.getTrailerNumber());
					if(car!=null) {
						map.put("guaNumber", car.getCarNumber());
					}else {
						map.put("guaNumber", null);
					}
				}else {
					map.put("guaPlate", null);
					map.put("guaNumber", null);
				}
			}else {
				map.put("carPlate", null);
				map.put("carNumber", null);
				map.put("guaPlate", null);
				map.put("guaNumber", null);
			}
			return new Result<Map<String,Object>>(map, 1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return new Result<>(1, e.getMessage());
		}
	}
	
}
